#include<unistd.h>
#include<stdio.h>
#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#define FILENAME "mkfifo"
int main()
{
   umask(0); //将文件默认掩码设置为0 使设置的权限符合预期
   if(mkfifo(FILENAME,0666)<0)
   {
       perror("mkfifo");
       return 1;
   }
   int fd=open(FILENAME,O_RDONLY);
   if(fd==-1)
   {
        perror("open5 failed");
       return 1;
   }
   char buffer[1024];
   while(1)
   {
    ssize_t n=read(fd,buffer,sizeof(buffer));
    if(n>0)
    {
        buffer[n-1]=0;//将输入的回车键的位置置0
        printf("client say: %s\n",buffer);
    }
    else if(n==0)
    {
        printf("client exit!\n");
        break;
    }
    else
    {
        printf("read failed!\n");
        break;
    }
   }
   close(fd);
    return 0;
}